package cn.com.xuhx.testMapper;

import cn.com.xuhx.mapper.UserMapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.*;

@RunWith(SpringRunner.class)
@SpringBootTest
public class DeleteTest {

    @Autowired
    private UserMapper userMapper;

    /**
     * 根据ID删除
     */
    @Test
    public void delByID(){
        //DELETE FROM T_USERS WHERE id=?
        int result = userMapper.deleteById(1506271115163095041L);
        System.out.println("变动数：" + result);
    }

    /**
     * 根据map条件删除
     */
    @Test
    public void delByMap(){
        //DELETE FROM T_USERS WHERE name = ? AND age = ?
        Map<String, Object> map = new HashMap<>();
        map.put("name","风晴雪");
        map.put("age",15);
        int result = userMapper.deleteByMap(map);
        System.out.println("变动数：" + result);
    }

    /**
     * 批量删除
     */
    @Test
    public void batchDel(){
        //DELETE FROM T_USERS WHERE id IN ( ? , ? , ? )
        List<Long> ids = Arrays.asList(1506276652982407169L,1506276758968250369L,1506276872025698305L);
        int result = userMapper.deleteBatchIds(ids);
        System.out.println("变动数：" + result);
    }
}
